package com.tdd.test;


import com.tdd.Lock;
import com.tdd.ZkTemplateImplLock;

/**
 * @author tudedong
 * @description
 * @date 2020-07-09 23:31:15
 */
public class OrderService implements Runnable {

    private OrderNumGenerator orderNumGenerator = new OrderNumGenerator();

    //private Lock lock = new ReentrantLock();
    private Lock lock = new ZkTemplateImplLock();

    @Override
    public void run() {
        getNumber();
    }

    private void getNumber(){
        try{
            lock.getLock();
            String orderNumber = orderNumGenerator.getOrderNumber();
            System.out.println(Thread.currentThread().getName() + "生成订单序列号为：" + orderNumber);
        }catch (Exception e){

        }finally {
            lock.unLock();
        }

    }

}
